#include <windows.h>
#include<stdio.h>
#include<string.h>
#include <conio.h>
#include "resource.h"
#include<stdlib.h>

const char g_szClassName[] = "myWindowClass";

   HDC hDC=NULL;
   HPEN hPen;
   PAINTSTRUCT Ps;
  HBRUSH NewBrush;
   int yes=0;
    int g=1;
	 HWND ret1,retro;
	 int nr,cx=19;
	  int m=0;
      char v[10]; 
	   int ok=0;
	  int h,j,k,l;
	  int nrect=24;

typedef struct drept
  {   int a;
      int b;
	  int c;
	  int d;
	 drept *left;
	 drept* right;
	 drept* center;
  }drept;

     drept *first=NULL;
	 drept t[30]={{25,0,350,400},{0,250,500,500},{30,25,150,200},{75,5,200,395},{225,25,345,275},{10,300,160,495},{360,255,495,475},{35,150,60,195},{85,30,145,75},{85,125,145,175},{175,10,195,390},{80,210,190,275},{315,30,340,270},{230,250,335,195},{15,450,50,490},{55,305,155,465},{365,280,490,375},{400,260,450,470},{425,325,475,425}};
	 drept arbore[30]={
	{280,20,310,50},{310,20,340,50},
	{180,120,210,150},{210,120,240,150},{240,120,270,150},
	{385,120,415,150},{415,120,445,150},
	{85,220,115,250},{115,220,145,250},{145,220,175,250},
	{180,220,210,250},{210,220,240,250},
	{275,220,305,250},{305,220,335,250},
	{370,220,400,250},{400,220,430,250},
	{465,220,495,250},{495,220,525,250},{525,220,555,250},
	{340,20,370,50},{445,120,475,150},{240,220,270,250},{335,220,365,250},{430,220,460,250}
				};

	 char ndr[]={"19"};
	 int nrd=19;
   void creare() 
	     {   if(first==NULL)
			   {   
				      first=(drept*)malloc(sizeof(drept));
				       first->center=(drept*)malloc(sizeof(drept));
				      first->center->a=t[1].a;
	                  first->center->b=t[1].b;
					  first->center->c=t[1].c;
					   first->center->d=t[1].d;
					   
					   first->left=(drept*)malloc(sizeof(drept));
	                   first->left->a=t[0].a;
					   first->left->b=t[0].b;
					   first->left->c=t[0].c;
					   first->left->d=t[0].d;
					   first->right=(drept*)malloc(sizeof(drept));
	                   first->right=NULL;
	             }
	            first->left->center=(drept*)malloc(sizeof(drept));
	            first->left->center->a=t[3].a;
			    first->left->center->b=t[3].b;
			    first->left->center->c=t[3].c;
			    first->left->center->d=t[3].d;

			    first->left->center->left=(drept*)malloc(sizeof(drept));
			    first->left->center->left->a=t[2].a;
			    first->left->center->left->b=t[2].b;
			    first->left->center->left->c=t[2].c;
				first->left->center->left->d=t[2].d;

				first->left->center->right=(drept*)malloc(sizeof(drept));
				first->left->center->right->a=t[4].a;
				first->left->center->right->b=t[4].b;
				first->left->center->right->c=t[4].c;
				first->left->center->right->d=t[4].d;

				 first->center->center=(drept*)malloc(sizeof(drept));
				 first->center->center->a=t[6].a;
				 first->center->center->b=t[6].b;
				 first->center->center->c=t[6].c;
			     first->center->center->d=t[6].d;
	                 
			     first->center->center->left=(drept*)malloc(sizeof(drept));
				 first->center->center->left->a=t[5].a;
				 first->center->center->left->b=t[5].b;
				 first->center->center->left->c=t[5].c;
				 first->center->center->left->d=t[5].d;

			     first->center->center->right=(drept*)malloc(sizeof(drept));
				 first->center->center->right=NULL;

				 first->left->center->left->center=(drept*)malloc(sizeof(drept));
			     first->left->center->left->center->a=t[8].a;
			     first->left->center->left->center->b=t[8].b;
				 first->left->center->left->center->c=t[8].c;
				 first->left->center->left->center->d=t[8].d;
				 first->left->center->left->center->center=(drept*)malloc(sizeof(drept));
				 first->left->center->left->center->center=NULL;

				 first->left->center->left->center->left=(drept*)malloc(sizeof(drept));
				 first->left->center->left->center->left->a=t[7].a;
				 first->left->center->left->center->left->b=t[7].b;
				 first->left->center->left->center->left->c=t[7].c;
				 first->left->center->left->center->left->d=t[7].d;
				 first->left->center->left->center->left->center=(drept*)malloc(sizeof(drept));
				 first->left->center->left->center->left->center=NULL;

							    first->left->center->left->center->right=(drept*)malloc(sizeof(drept));
                                first->left->center->left->center->right->a=t[9].a;
								first->left->center->left->center->right->b=t[9].b;
								first->left->center->left->center->right->c=t[9].c;
								first->left->center->left->center->right->d=t[9].d;
								first->left->center->left->center->right->center=(drept*)malloc(sizeof(drept));
					        	first->left->center->left->center->right->center=NULL;

								first->left->center->center=(drept*)malloc(sizeof(drept));
								first->left->center->center->a=t[11].a;
								first->left->center->center->b=t[11].b;
								first->left->center->center->c=t[11].c;
								first->left->center->center->d=t[11].d;
								first->left->center->center->center=(drept*)malloc(sizeof(drept));
								first->left->center->center->center=NULL;

								first->left->center->center->left=(drept*)malloc(sizeof(drept));
								first->left->center->center->left->a=t[10].a;
								first->left->center->center->left->b=t[10].b;
								first->left->center->center->left->c=t[10].c;
								first->left->center->center->left->d=t[10].d;
								first->left->center->center->left->center=(drept*)malloc(sizeof(drept));
								first->left->center->center->left->center=NULL;

								first->left->center->center->right=(drept*)malloc(sizeof(drept));
							    first->left->center->center->right=NULL;

								first->left->center->right->center=(drept*)malloc(sizeof(drept));
								first->left->center->right->center->a=t[13].a;
								first->left->center->right->center->b=t[13].b;
								first->left->center->right->center->c=t[13].c;
								first->left->center->right->center->d=t[13].d;
								first->left->center->right->center->center=(drept*)malloc(sizeof(drept));
								first->left->center->right->center->center=NULL;

								first->left->center->right->center->left=(drept*)malloc(sizeof(drept));
								first->left->center->right->center->left->a=t[12].a;
								first->left->center->right->center->left->b=t[12].b;
								first->left->center->right->center->left->c=t[12].c;
								first->left->center->right->center->left->d=t[12].d;
								first->left->center->right->center->left->center=(drept*)malloc(sizeof(drept));
								first->left->center->right->center->left->center=NULL;


					        	first->left->center->right->center->right=(drept*)malloc(sizeof(drept));
								first->left->center->right->center->right=NULL;
								first->center->center->left->center=(drept*)malloc(sizeof(drept));
								first->center->center->left->center->a=t[15].a;
								first->center->center->left->center->b=t[15].b;
								first->center->center->left->center->c=t[15].c;
								first->center->center->left->center->d=t[15].d;
								first->center->center->left->center->center=(drept*)malloc(sizeof(drept));
								first->center->center->left->center->center=NULL;

								first->center->center->left->center->left=(drept*)malloc(sizeof(drept));
								first->center->center->left->center->left->a=t[14].a;
							    first->center->center->left->center->left->b=t[14].b;
							    first->center->center->left->center->left->c=t[14].c;
							    first->center->center->left->center->left->d=t[14].d;
								first->center->center->left->center->left->center=(drept*)malloc(sizeof(drept));
	                            first->center->center->left->center->left->center=NULL;


			    				first->center->center->left->center->right=(drept*)malloc(sizeof(drept));
								first->center->center->left->center->right=NULL;
								first->center->center->center=(drept*)malloc(sizeof(drept));
								first->center->center->center->a=t[17].a;	
							    first->center->center->center->b=t[17].b;
								first->center->center->center->c=t[17].c;
								first->center->center->center->d=t[17].d;
								first->center->center->center->center=(drept*)malloc(sizeof(drept));
								first->center->center->center->center=NULL;

								first->center->center->center->left=(drept*)malloc(sizeof(drept));
								first->center->center->center->left->a=t[16].a;
								first->center->center->center->left->b=t[16].b;
								first->center->center->center->left->c=t[16].c;
								first->center->center->center->left->d=t[16].d;
								first->center->center->center->left->center=(drept*)malloc(sizeof(drept));
                                first->center->center->center->left->center=NULL;

								first->center->center->center->right=(drept*)malloc(sizeof(drept));
								first->center->center->center->right->a=t[18].a;
							    first->center->center->center->right->a=t[18].a;
								first->center->center->center->right->a=t[18].a;
								first->center->center->center->right->a=t[18].a;
								first->center->center->center->right->center=(drept*)malloc(sizeof(drept));
							    first->center->center->center->right->center=NULL;

	          }
  
   

 typedef struct coord{
    int x1;
    int y1;
    int x2;
    int y2;
     }cord;

  cord e,kl;
     char w[10];
	 int n;
  void search(int y)
	   {	 e.x1=0;
			 e.y1=0; 
			 e.x2=0; 
			 e.y2=0;
			 kl.x1=0;
			 kl.y1=0; 
			 kl.x2=0; 
			 kl.y2=0;
           for(int f=0;f<nrd;f++)
			   if(y==f)
			   {  e.x1=t[y].a;
		          e.y1=t[y].b;
				  e.x2=t[y].c;
				  e.y2=t[y].d;}
		   for(int v=0;v<nrect;v++)
				if(v==y)
				{	kl.x1=arbore[y].a;
			       kl.y1=arbore[y].b; 
			       kl.x2=arbore[y].c; 
			       kl.y2=arbore[y].d;
			   }

     	 }
  void insert (int h,int j,int k,int l )
      {  drept* s=(drept*)malloc(sizeof(drept));
            s=first;
	  
		if (s->left->center->center->right==NULL)
			{s->left->center->center->right=(drept*)malloc(sizeof(drept));
			s->left->center->center->right->a=h;
			s->left->center->center->right->b=j;
			s->left->center->center->right->c=k;
			s->left->center->center->right->d=l;
	    	return;	
		}
		if (s->left->center->right->center->right==NULL)
			{s->left->center->right->center->right=(drept*)malloc(sizeof(drept));
		     s->left->center->right->center->right->a=h;
		     s->left->center->right->center->right->b=j;
			 s->left->center->right->center->right->c=k;
			 s->left->center->right->center->right->d=l;
			  return;	
		}
		if (s->center->center->left->center->right==NULL)
		    {s->center->center->left->center->right=(drept*)malloc(sizeof(drept));
				s->center->center->left->center->right->a=h;
		     s->center->center->left->center->right->b=j;
			 s->center->center->left->center->right->c=k;
			 s->center->center->left->center->right->d=l;
			return;    
		}
		if (s->center->center->center->right->center==NULL)
			{ s->center->center->center->right->center=(drept*)malloc(sizeof(drept));
			s->center->center->center->right->center->a=h;
			s->center->center->center->right->center->b=j;
			s->center->center->center->right->center->c=k;
			s->center->center->center->right->center->d=l;
		   return;	
		}
		if( s->center->center->center->left->center==NULL)
			{s->center->center->center->left->center=(drept*)malloc(sizeof(drept));
			s->center->center->center->left->center->a=h;
			s->center->center->center->left->center->b=j;
			s->center->center->center->left->center->c=k;
			s->center->center->center->left->center->d=l;
		   return;	
		}
		if(s->center->center->center->center==NULL)
		   {s->center->center->center->center=(drept*)malloc(sizeof(drept));
		   s->center->center->center->center->a=h;
		   s->center->center->center->center->b=j;
		   s->center->center->center->center->c=k;
		   s->center->center->center->center->d=l;
		   return;
		}//14
		  if (s->center->center->left->center->left->center==NULL)
		   {s->center->center->left->center->left->center=(drept*)malloc(sizeof(drept));
		   s->center->center->left->center->left->center->a=h;
		   s->center->center->left->center->left->center->b=j;
		   s->center->center->left->center->left->center->c=k;
		   s->center->center->left->center->left->center->d=l;
	          return; 
		  }//15
		  if (s->center->center->left->center->center==NULL)
		    { s->center->center->left->center->center=(drept*)malloc(sizeof(drept));
			s->center->center->left->center->center->a=h;
			s->center->center->left->center->center->b=j;
			s->center->center->left->center->center->c=k;
			s->center->center->left->center->center->d=l;
			  return;  
		  }//12
		  if(s->left->center->right->center->left->center==NULL)
		   {s->left->center->right->center->left->center=(drept*)malloc(sizeof(drept));
		    s->left->center->right->center->left->center->a=h;
		   s->left->center->right->center->left->center->b=j;
		   s->left->center->right->center->left->center->c=k;
		   s->left->center->right->center->left->center->d=l;
		     return; 
		  }//13
		  if(s->left->center->right->center->center==NULL)
		   {s->left->center->right->center->center=(drept*)malloc(sizeof(drept));
		    s->left->center->right->center->center->a=h;
		   s->left->center->right->center->center->b=j;
		   s->left->center->right->center->center->c=k;
		   s->left->center->right->center->center->d=l;
			 return;
		   }//10
	  if(s->left->center->center->left->center==NULL)
		    {s->left->center->center->left->center=(drept*)malloc(sizeof(drept));
			s->left->center->center->left->a=h;
			s->left->center->center->left->center->b=j;
			s->left->center->center->left->center->c=k;
			s->left->center->center->left->center->d=l;
			 return; 
		   }//11
		  if(s->left->center->center->center==NULL)
		    {s->left->center->center->center=(drept*)malloc(sizeof(drept));
				s->left->center->center->center->a=h;
			s->left->center->center->center->b=j;
			s->left->center->center->center->c=k;
			s->left->center->center->center->d=l;
		     return; 
		    }//9
		  if ( s->left->center->left->center->right->center==NULL)
		    { s->left->center->left->center->right->center=(drept*)malloc(sizeof(drept));
			s->left->center->left->center->right->center->a=h;
			s->left->center->left->center->right->center->b=j;
			s->left->center->left->center->right->center->c=k;
			s->left->center->left->center->right->center->d=l;
		     return;  
		   }
		   if(s->left->center->left->center->left->center==NULL)
		    {s->left->center->left->center->left->center=(drept*)malloc(sizeof(drept));
				s->left->center->left->center->left->center->a=h;
			s->left->center->left->center->left->center->b=j;
			s->left->center->left->center->left->center->c=k;
			s->left->center->left->center->left->center->d=l;
		     return;
		   }
		   if(s->left->center->left->center->center==NULL)
		    {s->left->center->left->center->center=(drept*)malloc(sizeof(drept));
				s->left->center->left->center->center->a=h;
			s->left->center->left->center->center->b=j;
			s->left->center->left->center->center->c=k;
			s->left->center->left->center->center->d=l;
		     return;
		   }
      }
  

   void del(int d)
      {  drept* s=(drept*)malloc(sizeof(drept));
         s=first;
                if(d==8)
		 if (s->left->center->left->center->center==NULL)
		  {  drept *aux= s->left->center->left->center;
		  s->left->center->left->center=NULL;
			  free(aux);
			  return;
		  }
				       if(d==7)
		 if (s->left->center->left->center->left->center==NULL)
		  {  drept *aux= s->left->center->left->center->left->center;
		 s->left->center->left->center->left->center=NULL;
			  free(aux);  
			  return;
		  }
					   if (d==9)
		 if (s->left->center->left->center->right->center==NULL)
		  {  drept *aux=s->left->center->left->center->right->center;
		 s->left->center->left->center->right->center=NULL;
			  free(aux);  
			  return;
		  }
					   if(d==11)
           if(s->left->center->center->center==NULL)
		   { drept *aux=s->left->center->center->center;
		 s->left->center->center->center=NULL;
			  free(aux);
			  return;
		   }
					   if(d==10)
            if(s->left->center->center->left->center==NULL)
			 { drept*aux=s->left->center->center->left->center;
					   s->left->center->center->left->center=NULL;
					   free(aux);
					   return;
			 }
					   if(d==13)
             if(s->left->center->right->center->center==NULL)
			  {drept*aux=s->left->center->right->center->center;
					   s->left->center->right->center->center=NULL;
					   free(aux);
					   return;
			  }
					   if(d==12)
			if(s->left->center->right->center->left->center==NULL)
			  {drept*aux=s->left->center->right->center->left->center;
					   s->left->center->right->center->left->center=NULL;
					   free(aux);
					   return;
			  }

               					   if(d==15)
			if(s->center->center->left->center->center==NULL)
			  {drept*aux=s->center->center->left->center->center;
					s->center->center->left->center->center=NULL;
					   free(aux);
					   return;
			  }
								    if(d==14)
			if(s->center->center->left->center->center==NULL)
			  {drept*aux=s->center->center->left->center->center;
					s->center->center->left->center->center=NULL;
					   free(aux);
					   return;
			  }
									if(d==16)
			if(s->center->center->center->left->center==NULL)
			 {  drept*aux=s->center->center->center->left;
			     s->center->center->center->left=NULL;
			     free(aux);
				 return;
			}
									if(d==17)
			if(s->center->center->center->center==NULL)
			 {  drept*aux=s->center->center->center;
			     s->center->center->center=NULL;
			     free(aux);
				 return;
			}
									if(d==18)
		   if(s->center->center->center->right->center==NULL)
		      {drept*aux=s->center->center->center->right;
                    s->center->center->center->right=NULL;
					free(aux);
					return;
		       }


      }
 //delete
   BOOL CALLBACK Dialog5(HWND hwnd,UINT msg,WPARAM wParam, LPARAM lParam)
     { 
	     switch(msg)
           {  
			  case WM_INITDIALOG:
			      return TRUE;

			  case WM_COMMAND:
				switch  (LOWORD(wParam))
				 {
					 case IDOK:
						m++;
						GetDlgItemText(hwnd,IDC_EDIT1,v,10);
						search(atoi(v));
						creare();
						del(atoi(v));
						ok=0;
						EndDialog(hwnd, IDOK);
					    break;
					case IDCANCEL:
						EndDialog(hwnd, IDCANCEL);
					     break;
	
				 }
				break;
	 
		    default:return FALSE;
	       }
	    return TRUE;
     }
//insert
  typedef struct corm{
     char min1[3];
     char min2[3];
     char max1[3];
     char max2[3];
         }cm;

       cm dr[50];
	 
	 //insert
   BOOL CALLBACK Dialog4(HWND hwnd,UINT msg,WPARAM wParam, LPARAM lParam)
   {  
	   switch(msg)
        {  
			case WM_INITDIALOG:
			  return TRUE;

			case WM_COMMAND:
				switch  (LOWORD(wParam))
				{
					 case IDOK:
						 
						 GetDlgItemText(hwnd,IDC_EDIT1,dr[ok].min1,3);
						 h=atoi(dr[ok].min1);
						 GetDlgItemText(hwnd,IDC_EDIT2,dr[ok].min2,3);
						 j=atoi(dr[ok].min2);
						 GetDlgItemText(hwnd,IDC_EDIT3,dr[ok].max1,3);
						 k=atoi(dr[ok].max1);
						 GetDlgItemText(hwnd,IDC_EDIT4,dr[ok].max2,3);
						 l=atoi(dr[ok].max2);
						 t[nrd].a=atoi(dr[ok].min1);
						 t[nrd].b=atoi(dr[ok].min2);
						 t[nrd].c=atoi(dr[ok].max1);
						 t[nrd].d=atoi(dr[ok].max2);
						   arbore[nrect].a=atoi(dr[ok].min1);
						   arbore[nrect].b=atoi(dr[ok].min2);
						   arbore[nrect].c=atoi(dr[ok].max1);
						   arbore[nrect].d=atoi(dr[ok].max2);
						   ok++;
						   nrd++;
						   nrect++;
						   creare();
						 insert(h,j,k,l);
						 m=0;
						 EndDialog(hwnd, IDOK);
					     break;

					case IDCANCEL:
						EndDialog(hwnd, IDCANCEL);
					    break;
	
				}
				break;
	 
		  default:return FALSE;
	   }
	   return TRUE;
    }
//search
   BOOL CALLBACK Dialog3(HWND hwnd,UINT msg,WPARAM wParam, LPARAM lParam)
     { 
     
   	    switch(msg)
         {  
			case WM_INITDIALOG:
				return TRUE;

			case WM_COMMAND:
				switch  (LOWORD(wParam))
				 {
					case IDOK:
						yes++;			
						GetDlgItemText(hwnd,IDC_EDIT1,w,50);
						search(atoi(w));
						ok=0;
						m=0;
						EndDialog(hwnd,IDOK);
					 break;
					case IDCANCEL:
						EndDialog(hwnd, IDCANCEL);
					 break;
	
				}
			   break;
	
			case WM_PAINT:
				hDC=BeginPaint(hwnd,&Ps);
				SetBkColor(hDC,RGB(255,255,5));
			    SetTextColor(hDC,RGB(5,255,25));
				TextOut(hDC,175,167,ndr,strlen(ndr));
				EndPaint(hwnd,&Ps);
			  break;
		    default:return FALSE;
	    }
	     return TRUE;
    }
    BOOL CALLBACK  wet1(HWND hwnd, UINT Message,WPARAM wParam,LPARAM lParam )
   { 
       
      switch(Message)
	     {   
		 case WM_INITDIALOG:
			return TRUE;
		 case WM_COMMAND:
			switch(LOWORD(wParam))
			  {
				  case IDC_BUTTON1:
					  nr=1;
					  if(cx>22)
					EnableWindow(retro,FALSE);
					ShowWindow(hwnd,SW_PARENTOPENING);
			        ShowWindow(hwnd,SW_NORMAL);
					break;

				  default :return FALSE;
					 

			  }
		     break;
		 default: return FALSE;
	  }
	  return TRUE;
   }

  BOOL CALLBACK  wet(HWND hwnd, UINT Message,WPARAM wParam,LPARAM lParam )
   { 
       
      switch(Message)
	     {   
		 case WM_INITDIALOG:
			return TRUE;
		 case WM_COMMAND:
			switch(LOWORD(wParam))
			  {
				  case IDC_BUTTON1:
	                n=1;
					if(g>=19)
						EnableWindow(ret1,FALSE);
					 ShowWindow(hwnd,SW_PARENTOPENING);
			       ShowWindow(hwnd,SW_NORMAL);
				 break;


				  default :return FALSE;
					 

			  }
		     break;
		 default: return FALSE;
	  }
	  return TRUE;
   }
  BOOL CALLBACK AboutDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
   {
	
	 switch(msg)
	  {
		 case WM_INITDIALOG:
			return TRUE;
		 case WM_COMMAND:
			switch(LOWORD(wParam))
			  {
				case IDOK:
					//MessageBox(NULL, "OK!", "Error!", MB_ICONEXCLAMATION | MB_OK);
					EndDialog(hwnd,IDOK);
				    break;
				//case IDCANCEL:
				//	//MessageBox(NULL, "CANCEL!", "Error!", MB_ICONEXCLAMATION | MB_OK);
				//	EndDialog(hwnd,IDCANCEL);
				//    break;
			  }
		     break;
		 default: return FALSE;
	  }
	 return TRUE;
   }
  
 //Step 4: the Window Procedure
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 {
	//creare();
	
	POINT Pt[100];
	int lpPts[] = { 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4 };
	//R1
	//Stanga sus//
	Pt[0].x = 25;
	Pt[0].y = 0;
	//Stanga jos
	Pt[1].x = 25;
	Pt[1].y = 400;
	//Dreapta jos//
	Pt[2].x = 350;
	Pt[2].y = 400;
	//Dreapta sus
	Pt[3].x = 350;
	Pt[3].y = 0;

	//R2
	Pt[4].x = 0;
	Pt[4].y = 250;
	Pt[5].x = 0;
	Pt[5].y = 500;
	Pt[6].x = 500;
	Pt[6].y = 500;
	Pt[7].x = 500;
	Pt[7].y = 250;

	//R3
	Pt[8].x = 30;
	Pt[8].y = 25;
	Pt[9].x = 30;
	Pt[9].y = 200;
	Pt[10].x = 150;
	Pt[10].y = 200;
	Pt[11].x = 150;
	Pt[11].y = 25;
	
	//R4
	Pt[12].x = 75;
	Pt[12].y = 5;
	Pt[13].x = 75;
	Pt[13].y = 395;
	Pt[14].x = 200;
	Pt[14].y = 395;
	Pt[15].x = 200;
	Pt[15].y = 5;
	
	//R5
	Pt[16].x = 225;
	Pt[16].y = 25;
	Pt[17].x = 225;
	Pt[17].y = 275;
	Pt[18].x = 345;
	Pt[18].y = 275;
	Pt[19].x = 345;
	Pt[19].y = 25;
	
	//R6
	Pt[20].x = 10;
	Pt[20].y = 300;
	Pt[21].x = 10;
	Pt[21].y = 495;
	Pt[22].x = 160;
	Pt[22].y = 495;
	Pt[23].x = 160;
	Pt[23].y = 300;
	
	//R7
	Pt[24].x = 360;
	Pt[24].y = 255;
	Pt[25].x = 360;
	Pt[25].y = 475;
	Pt[26].x = 495;
	Pt[26].y = 475;
	Pt[27].x = 495;
	Pt[27].y = 255;

	//R8
	Pt[28].x = 35;
	Pt[28].y = 150;
	Pt[29].x = 35;
	Pt[29].y = 195;
	Pt[30].x = 60;
	Pt[30].y = 195;
	Pt[31].x = 60;
	Pt[31].y = 150;
	
	//R9
	Pt[32].x = 85;
	Pt[32].y = 30;
	Pt[33].x = 85;
	Pt[33].y = 75;
	Pt[34].x = 145;
	Pt[34].y = 75;
	Pt[35].x = 145;
	Pt[35].y = 30;

	//R10
	Pt[36].x = 85;
	Pt[36].y = 125;
	Pt[37].x = 85;
	Pt[37].y = 175;
	Pt[38].x = 145;
	Pt[38].y = 175;
	Pt[39].x = 145;
	Pt[39].y = 125;

	//R11
	Pt[40].x = 175;
	Pt[40].y = 10;
	Pt[41].x = 175;
	Pt[41].y = 390;
	Pt[42].x = 195;
	Pt[42].y = 390;
	Pt[43].x = 195;
	Pt[43].y = 10;

	//R12
	Pt[44].x = 80;
	Pt[44].y = 210;
	Pt[45].x = 80;
	Pt[45].y = 275;
	Pt[46].x = 190;
	Pt[46].y = 275;
	Pt[47].x = 190;
	Pt[47].y = 210;

	//R13
	Pt[48].x = 315;
	Pt[48].y = 30;
	Pt[49].x = 315;
	Pt[49].y = 270;
	Pt[50].x = 340;
	Pt[50].y = 270;
	Pt[51].x = 340;
	Pt[51].y = 30;

	//R14
	Pt[68].x = 230;
	Pt[68].y = 150;
	Pt[69].x = 230;
	Pt[69].y = 195;
	Pt[70].x = 335;
	Pt[70].y = 195;
	Pt[71].x = 335;
	Pt[71].y = 150;

	//R15
	Pt[52].x = 15;
	Pt[52].y = 450;
	Pt[53].x = 15;
	Pt[53].y = 490;
	Pt[54].x = 50;
	Pt[54].y = 490;
	Pt[55].x = 50;
	Pt[55].y = 450;

	//R16
	Pt[56].x = 55;
	Pt[56].y = 305;
	Pt[57].x = 55;
	Pt[57].y = 465;
	Pt[58].x = 155;
	Pt[58].y = 465;
	Pt[59].x = 155;
	Pt[59].y = 305;

	//R17
	Pt[60].x = 365;
	Pt[60].y = 280;
	Pt[61].x = 365;
	Pt[61].y = 375;
	Pt[62].x = 490;
	Pt[62].y = 375;
	Pt[63].x = 490;
	Pt[63].y = 280;

	//R18
	Pt[64].x = 400;
	Pt[64].y = 260;
	Pt[65].x = 400;
	Pt[65].y = 470;
	Pt[66].x = 450;
	Pt[66].y = 470;
	Pt[67].x = 450;
	Pt[67].y = 260;

	//R19
	Pt[64].x = 425;
	Pt[64].y = 325;
	Pt[65].x = 425;
	Pt[65].y = 425;
	Pt[66].x = 475;
	Pt[66].y = 425;
	Pt[67].x = 475;
	Pt[67].y = 325;
	
	int ret;
    switch(msg)
      {  case WM_CREATE:
	         ret1=CreateDialog(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_FORMVIEW),hwnd,wet);
			 if(ret1)
				 ShowWindow(ret1,SW_SHOW);
			   retro=CreateDialog(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_FORMVIEW1),hwnd,wet1);
			   if(retro)
				  ShowWindow(retro,SW_SHOW);
			    EndDialog(hwnd,IDOK);
		        break;
	  case WM_COMMAND:
			switch(LOWORD(wParam))
			{
		       case ID_FILE_HELP :
			       DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DIALOG), hwnd, AboutDlgProc);
			       ShowWindow(hwnd,SW_PARENTOPENING);
			       ShowWindow(hwnd,SW_NORMAL);
			       InvalidateRect(hwnd,NULL,TRUE);
			       break;

			   case ID_FILE_SEARCH :
				   ret=DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DIALOG2), hwnd, Dialog3);
				   if(ret==IDOK)
				   ShowWindow(hwnd,SW_PARENTOPENING),
			       ShowWindow(hwnd,SW_NORMAL),
				   InvalidateRect(hwnd,NULL,TRUE);
			       break;
			 case ID_FILE_DELETE :
			       DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DIALOG1), hwnd, Dialog5);
				   ShowWindow(hwnd,SW_PARENTOPENING),
			       ShowWindow(hwnd,SW_NORMAL),
				   InvalidateRect(hwnd,NULL,TRUE);
			       break;

		    case ID_FILE_INSERT :
			      DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DIALOG3), hwnd, Dialog4);
			      ShowWindow(hwnd,SW_PARENTOPENING);
			      ShowWindow(hwnd,SW_NORMAL);
			     InvalidateRect(hwnd,NULL,TRUE);
			     break;

			}
		   break;

        case WM_CLOSE:
            DestroyWindow(hwnd);
            break;
					
	    case WM_PAINT:

			hDC=BeginPaint(hwnd,&Ps);
			hPen=CreatePen(PS_COSMETIC,1,RGB(255,25,5));
			SetBkColor(hDC,RGB(255,255,255));
			SelectObject(hDC,hPen);
			if(n==1)
			{
			PolyPolygon(hDC, Pt, lpPts, g);
				for(int z=0;z<g;z++)
		          { RoundRect(hDC,arbore[z].a+500,arbore[z].b,arbore[z].c+500,arbore[z].d,20,20);
			         TextOut(hDC,arbore[z].a+505,arbore[z].b+5,"R",1);}
			         g++;
			       }
			      if(nr==1)
				  {  PolyPolygon(hDC, Pt, lpPts, 19);
					  for(cx=19;cx<24;cx++)
					  RoundRect(hDC,arbore[cx].a+500,arbore[cx].b,arbore[cx].c+500,arbore[cx].d,20,20);
					                MoveToEx(hDC, 795, 50, NULL);LineTo(hDC, 725, 120);
			                        MoveToEx(hDC, 695, 150, NULL);LineTo(hDC,630,220);
									MoveToEx(hDC, 725, 150, NULL);LineTo(hDC,725,220);
									MoveToEx(hDC, 755, 150, NULL);LineTo(hDC,820,220);
									MoveToEx(hDC, 825, 50, NULL);LineTo(hDC,930,120);
									MoveToEx(hDC, 900, 150, NULL);LineTo(hDC,915,220);
									MoveToEx(hDC, 930, 150, NULL);LineTo(hDC,1010,220);

				  
				  }
				

			  //delete
			 for (int o=0;o<m;o++)
			   {  if(atoi(v)==30)
			        {    hPen=CreatePen(PS_COSMETIC,1,RGB(255,255,255));
				         SelectObject(hDC,hPen);
						 RoundRect(hDC,arbore[14].a+500,arbore[14].b,arbore[14].c+500,arbore[14].d,20,20);
						 RoundRect(hDC,arbore[15].a+500,arbore[15].b,arbore[15].c+500,arbore[15].d,20,20);
						 RoundRect(hDC,arbore[15].a+500+30,arbore[15].b,arbore[15].c+500+30,arbore[15].d,20,20);
						 //stergerea liniei
						 MoveToEx(hDC, 900, 150, NULL);LineTo(hDC,915,220);
						 SetTextColor(hDC,RGB(250,155,255));
			             TextOut(hDC,445+505,120+5,"R",1);
						

			         }
				   hPen=CreatePen(PS_COSMETIC,1,RGB(255,25,5));
				   SelectObject(hDC,hPen);
				   PolyPolygon(hDC, Pt, lpPts, 19);
				 hPen=CreatePen(PS_COSMETIC,1,RGB(255,255,255));
			     SelectObject(hDC,hPen);
				 Rectangle(hDC,e.x1,e.y1,e.x2,e.y2);
				   hPen=CreatePen(PS_COSMETIC,1,RGB(255,25,5));
				   SelectObject(hDC,hPen);
				   RoundRect(hDC,kl.x1+500,kl.y1,kl.x2+500,kl.y2,20,20);}
			
		
			      //insert
			 for(int j=0;j<ok;j++)
			   {hPen=CreatePen(PS_COSMETIC,1,RGB(255,25,5));
				    SelectObject(hDC,hPen);
				    PolyPolygon(hDC, Pt, lpPts, 19);
				     hPen=CreatePen(PS_COSMETIC,1,RGB(25,5,255));
			         SelectObject(hDC,hPen);
					 Rectangle(hDC,atoi(dr[j].min1) ,atoi(dr[j].min2),atoi(dr[j].max1),atoi(dr[j].max2));}
				  
			  if(ok)
			   {
			      if(ok==1)
				    { SetTextColor(hDC,RGB(250,5,255));
			        TextOut(hDC,240+505,220+5,"R",1);}
				
				   if(ok==2)
					{SetTextColor(hDC,RGB(250,5,255));
			        TextOut(hDC,445+505,120+5,"R",1);
					}
				 
				  if(ok==3)
					{  hPen=CreatePen(PS_COSMETIC,1,RGB(250,5,255));
			           SelectObject(hDC,hPen);
					   RoundRect(hDC,115+500,220+100,145+500,250+100,20,20);
					   MoveToEx(hDC,130+500,220+30,NULL);
					   LineTo(hDC,130+500,220+100);
					   SetTextColor(hDC,RGB(250,5,255));
					   TextOut(hDC,115+505,220+105,"R",1);
					   RoundRect(hDC,145+500,220+100,175+500,250+100,20,20);
					   RoundRect(hDC,85+500,220+100,115+500,250+100,20,20);
					}
				
				   
			  }
			  	 //search
			   if (yes)  
				   yes=0,
			       hPen=CreatePen(PS_COSMETIC,1,RGB(255,25,5)),
				   SelectObject(hDC,hPen),
				   PolyPolygon(hDC, Pt, lpPts, 19),
			     hPen=CreatePen(PS_COSMETIC,1,RGB(25,255,5)),
			     SelectObject(hDC,hPen),
			     Rectangle(hDC,e.x1,e.y1,e.x2,e.y2),
			     NewBrush=CreateSolidBrush(RGB(25,255,5)),
				 SelectObject(hDC,NewBrush),
			     RoundRect(hDC,kl.x1+500,kl.y1,kl.x2+500,kl.y2,20,20),
				 DeleteObject(NewBrush);
			     EndPaint(hwnd,&Ps);
			break;

        case WM_DESTROY:
            PostQuitMessage(0);
            break;
        default:
            return DefWindowProc(hwnd, msg, wParam, lParam);
    }
       return 0;
  }

  int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
   {
      WNDCLASSEX wc;
       HWND hwnd;
        MSG Msg;

//    Step 1: Registering the Window Class
     wc.cbSize        = sizeof(WNDCLASSEX);
     wc.style         = 0;
     wc.lpfnWndProc   = WndProc;
     wc.cbClsExtra    = 0;
     wc.cbWndExtra    = 0;
     wc.hInstance     = hInstance;
     wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
     wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
	 wc.lpszMenuName  = MAKEINTRESOURCE(IDR_MENU1);
     wc.lpszClassName = g_szClassName;
     wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

    if(!RegisterClassEx(&wc))
      {
         MessageBox(NULL, "Window Registration Failed!", "Error!",MB_ICONEXCLAMATION | MB_OK);
         return 0;
      }

  //   Step 2: Creating the Window
       hwnd = CreateWindowEx( WS_EX_CLIENTEDGE,g_szClassName,"R Tree Demonstrator!",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, CW_USEDEFAULT, 1300,950,NULL, NULL, hInstance, NULL);

    if(hwnd == NULL)
       {
            MessageBox(NULL, "Window Creation Failed!", "Error!",MB_ICONEXCLAMATION | MB_OK);
            return 0;
       }

     ShowWindow(hwnd, nCmdShow);
     UpdateWindow(hwnd);

//     Step 3: The Message Loop
      while(GetMessage(&Msg, NULL, 0, 0) > 0)
       {
         TranslateMessage(&Msg);
         DispatchMessage(&Msg);
       }
     return Msg.wParam;

	getch();
  }
